﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ApprovalFlow.Interface;
using ApprovalFlow.Models;

namespace ApprovalFlow.Services
{
    public class WorkflowRegistry : IWorkflowRegistry
    {
        static WorkflowDefinition _definition;

        public WorkflowDefinition GetDefinition(string process_code, int? version = null)
        {
            if (_definition is not null)
                return _definition;
            _definition = new();

            IStepDescription root = new StartStepDescription();
            var parent = root;
            IStepDescription step = new ApprovalStepDescription() { Name = "直接主管" };
            parent.ChildNode = step;
            parent = step;

            step = new IfStepDescription() { Name = "条件分支" };
            parent.ChildNode = step;
            if (step is IfStepDescription ifStep)
            {
                ifStep.AddCondition(new ConditionDescription() { Name = "大于3天", ChildNode = new ApprovalStepDescription() { Name = "部门经理" } });
            }
            parent = step;

            step = new ApprovalStepDescription() { Name = "人事" };
            parent.ChildNode = step;
            parent = step;

            step = new WaitForStepDescription() { Name = "等待" };
            parent.ChildNode = step;
            parent = step;

            step = new ApprovalStepDescription() { Name = "通知" };
            parent.ChildNode = step;


            _definition.Root = root;
            return _definition;
        }
    }
}
